<!-- 首页 -->
<template>
	<view>
		<!-- 轮播图 -->
		<u-swiper height="72.6vw" keyName="image" radius="0" :list="bannerlist" indicator indicatorMode="dot" circular @click="clickBanner"></u-swiper>
		<u-navbar :safeAreaInsetTop="true" :fixed="true" :bgColor="bgColors">
			<view slot="left" class="u-flex search-box" style="width: 65vw;">
				<view class="u-flex m-flex-no u-flex-y-center" @click="regionShow = true">
					<u-icon name="dingwei" customPrefix="master" size="18" color="#333"></u-icon>
					<view class="u-m-l-20">{{ city }}</view>
					<u-line class="u-line" direction="col" margin="0 0 0 20rpx"></u-line>
				</view>
				<u-search placeholder="你想找哪里呢？" height="40" bgColor="transparent" :show-action="false" @click="nextNav('/pages/room/search?type=1')" :disabled="true"></u-search>
			</view>
		</u-navbar>
		<!-- 功能 -->
		<view class="u-p-t-20">
			<u-grid :border="false">
				<u-grid-item v-for="(item, index) in baseList" :key="index" @click="nextNav(item.url)">
					<u-icon size="50" :name="item.icon"></u-icon>
					<text class="u-m-t-20 m-font-b u-m-b-20" :class="!item.shan && (item.wenzi == '（免中介费）' || item.wenzi == '（购房返现）') ? 'm-c-r' : ''">
						{{ item.shan ? item.text : item.wenzi }}
					</text>
				</u-grid-item>
			</u-grid>
		</view>
		<!-- 列表 -->
		<view class="heighly"><newlist :list="dataList" :listHighly="highly" :listMore="listStatus" textType="在售"></newlist></view>
		<u-back-top :scrollTop="pagescrollTop" top="200"></u-back-top>
		<obtain :show="obtain" @showchange="obtain = false"></obtain>
		<u-picker :show="regionShow" keyName="name" :columns="[getcity]" :defaultIndex="defaultIndex" @cancel="regionShow = false" @confirm="confirm"></u-picker>
		<u-loading-page loading-text="内当家APP" :loading="pageLoad"></u-loading-page>
	</view>
</template>

<script>
export default {
	data() {
		return {
			bgColors: 'transparent',
			getcity: [],
			defaultIndex: [1],
			bannerlist: [],
			baseList: [
				{
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/index/1.png',
					text: '新房返利',
					wenzi: '（购房返现）',
					shan: true,
					url: '/pages/room/rebate'
				},
				{
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/index/2.png',
					text: '二手房源',
					wenzi: '（免中介费）',
					shan: true,
					url: '/pages/handhousing/handhousing'
				},
				{
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/index/3.png',
					text: '房屋租赁',
					wenzi: '（免中介费）',
					shan: true,
					url: '/pages/zufang/zufang'
				},
				{
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/index/4.png',
					text: '查学区',
					wenzi: '查学区',
					shan: false,
					url: 'no'
				},
				{
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/index/5.png',
					text: '当家活动',
					wenzi: '当家活动',
					shan: false,
					url: '/pages/christmasr/activitylist'
				},
				{
					icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/index/6.png',
					text: '小象旅游',
					wenzi: '小象旅游',
					shan: false,
					url: 'no'
				}
			],
			regionShow: false
		};
	},
	onPageScroll(e) {
		if (e.scrollTop < 100) {
			this.bgColors = 'transparent';
		} else {
			this.bgColors = '#fff';
		}
	},
	async onLoad(e) {
		if (e && e.scene) {
			uni.setStorageSync('agentid', e.scene);
		}
		let getcity = await this.require('getcity');
		if (getcity) {
			getcity.unshift({
				id: 0,
				name: '不限'
			});
			this.getcity = getcity;
			this.city = getcity[1] ? getcity[1].name : '东莞市';
			uni.setStorageSync('getcity', JSON.stringify(getcity));
		}
		this.path = 'propertieslist';
		this.params = {
			...this.params,
			pnum: this.pnum,
			city: this.city,
			loupanleixing: '新房'
		};
		await this.getList();
		let bannerlist = await this.require('bannerlist');
		if (bannerlist) {
			this.bannerlist = bannerlist;
		}
		setTimeout(() => {
			this.pageLoad = false;
		}, 1000);
		setInterval(() => {
			for (var i = 0; i < this.baseList.length; i++) {
				this.baseList[i].shan = !this.baseList[i].shan;
			}
		}, 1000);
		let cityall = await this.require('cityall');
		if (cityall) {
			cityall.unshift({
				name: '不限',
				child: [
					{
						name: '不限',
						child: [
							{
								name: '不限'
							}
						]
					}
				]
			});
			uni.setStorageSync('cityall', JSON.stringify(cityall));
		}
	},
	onShow() {
		this.xinxiao();
	},
	methods: {
		async confirm(e) {
			this.city = e.value[0].name;
			uni.setStorageSync('city', this.city);
			this.params = {
				p: 1,
				pnum: this.pnum,
				city: this.city,
				loupanleixing: '新房'
			};
			await this.getList();
			this.regionShow = false;
		},
		clickBanner(e) {
			this.nextNav(this.bannerlist[e].url);
		}
	}
};
</script>

<style lang="scss" scoped>
.search-box {
	background-color: #f6f6f6;
	border-radius: 50rpx;
	height: 60rpx;
	line-height: 60rpx;
	padding: 10rpx 15rpx;
}
</style>
